/* 
 * File:   main.cpp
 * @author: Diane <weis0258@d.umn.edu>
 * @author: Dan <hops0016@d.umn.edu>
 * @author: Tim <mill4138@d.umn.edu>
 *
 * Created on September 21, 2012, 11:18 AM
 */

#include <cstdlib>
#include <iostream>
//#include "FSBlock.h"
#include "Disk.h"
#include "FSBlock.h"

using namespace std;

int main(int argc, char** argv) {
    unsigned int num_blocks = 100;
    unsigned int blocksize  = Disk::DEFAULT_BLOCK_SIZE;
    const char *file = "disk1";
    Disk d(file, num_blocks, blocksize, false);

    int block_number = 0;

    unsigned char *a_buffer;
    FSBlock fb(block_number, Disk::DEFAULT_BLOCK_SIZE);

    a_buffer = new unsigned char[Disk::DEFAULT_BLOCK_SIZE];

for(;;) {
    int cmd = 0;
	printf("\nmain: Enter command:\n");
	printf("0) Exit program.\n");
	printf("1) Disk Test UI.\n");
    printf("2) FSBlock, run some tests.\n");

	printf("Enter command: ");
    if (scanf("%d", &cmd) != 1) {
        printf("ERROR: Couldn't read from user\n"); 
        continue;
   } 

	switch(cmd) {
		case 0:
			return(0);
		case 1:
            d.Test();
            break;
        case 2:
            d.ReadBlock(0, a_buffer);

            cout << "Disk:: Raw Read Disk Block" << endl;
            cout << "START";
            cout << a_buffer;
            cout << "END" << endl;


            cout << "FSBlock::Setbuffer...\n";
            fb.SetBuffer(a_buffer);
            cout << fb.GetBuffer();

            fb.SetInt(80429, 0);
            fb.SetInt(15, 2);
            cout << "\nResult from GetInt(2)\n";
            cout << fb.GetInt(2);
            cout << "\n";
            cout << "FSBlock::Write...\n";
            fb.Write(&d);
            cout << "FSBlock::Print...\n";
            fb.Print();
            
            break;
		default:
			printf("main: Bad Command!");
			break;
		}
	}
}

